package service

import (
	"vtrip/internal/model"
	"vtrip/pkg/app"
)

// GetAllArticleRequest 查询所有文章
type GetAllArticleRequest struct {
	Page     int `form:"page,default=0"`
	PageSize int `form:"page_size,default=0"`
}

// PublishArticleRequest 发布文章
type PublishArticleRequest struct {
	Title     string `form:"title" binding:"required"`
	CoverUrl  string `form:"cover_url"`
	Introduce string `form:"introduce" binding:"required"`
	Content   string `form:"content" binding:"required"`
}

// GetArticleDetailRequest 获取文章详细信息
type GetArticleDetailRequest struct {
	ArticleId int `form:"article_id" binding:"required"`
}

// LikeArticleRequest 为文章点赞
type LikeArticleRequest struct {
	ArticleId int `form:"article_id" binding:"required"`
}

// DislikeArticleRequest 取消点赞
type DislikeArticleRequest struct {
	ArticleId int `form:"article_id" binding:"required"`
}

func (svc Service) GetAllArticle(param *GetAllArticleRequest) ([]*model.ArticlePart, error) {
	return svc.dao.FindAllArticle(app.GetPageOffset(param.Page, param.PageSize), param.PageSize)
}

func (svc Service) PublishArticle(userId int, param *PublishArticleRequest) error {
	return svc.dao.CreateArticle(userId, param.Title,
		param.CoverUrl, param.Introduce, param.Content)
}

func (svc Service) GetArticleDetail(userId int, param *GetArticleDetailRequest) (*model.ArticleDetail, error) {
	return svc.dao.GetArticleDetail(userId, param.ArticleId)
}

func (svc Service) LikeArticle(userId int, param *LikeArticleRequest) error {
	return svc.dao.LikeArticle(userId, param.ArticleId)
}

func (svc Service) DisLikeArticle(userId int, param *DislikeArticleRequest) error {
	return svc.dao.DisLikeArticle(userId, param.ArticleId)
}
